${C.packageName(T.CONTROLLER)}

import cn.sh.ideal.portal.framework.persistence.util.Empty;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

<#list C.importName(T.SERVICE,T.DOMAIN) as import>
${import}
</#list>
<#list C.tableClass().types as type>
import ${type};
</#list>
<#list C.tableClass().types as type>
<#if type=="java.util.Date">
import java.text.SimpleDateFormat;
</#if>
</#list>
/**
  * ${module}Controller处理类
  * @author
  */
@Controller
@RequestMapping(value = "oa/app/${S.firstToLowerCase(C.className(T.DOMAIN))}")
public class ${C.className(T.CONTROLLER)}{

    @Autowired
    private ${C.className(T.SERVICE)} ${S.firstToLowerCase(C.className(T.SERVICE))};
    /**
      * 添加${module}
      */
    @RequestMapping(value = "/add.htm")
    public String add(HttpServletRequest request, Model model) throws Exception {
        ${C.className(T.DOMAIN)} ${S.firstToLowerCase(C.className(T.DOMAIN))} = new ${C.className(T.DOMAIN)}();
        <#list C.tableClass().propertyDescList as property>
        <#if property.classSimpleName == "Date">
        SimpleDateFormat sDFormat = new SimpleDateFormat("yyyy-MM-dd");
            <#break>
        </#if>
        </#list>

        <#list C.tableClass().propertyDescList as property>
        <#if property.classSimpleName == "Date">
        String ${property.propertyName} = request.getParameter("${property.propertyName}");
        Date ${property.propertyName}Format = null;
        if(!Empty.isEmpty(${property.propertyName})){
            ${property.propertyName}Format = sDFormat.parse(${property.propertyName});
        }
        <#else>
        ${property.classSimpleName} ${property.propertyName} = request.getParameter("${property.propertyName}");
        </#if>
        </#list>

        <#list C.tableClass().propertyDescList as property>
        <#if property.classSimpleName == "Date">
        if(!Empty.isEmpty(${property.propertyName}Format)){
               ${S.firstToLowerCase(C.className(T.DOMAIN))}.set${property.propertyNameUpCase}(${property.propertyName}Format);
        }
        <#else>
        ${S.firstToLowerCase(C.className(T.DOMAIN))}.set${property.propertyNameUpCase}(${property.propertyName});
        </#if>
        </#list>

        ${S.firstToLowerCase(C.className(T.SERVICE))}.save(${S.firstToLowerCase(C.className(T.DOMAIN))});
        return "";
    }
    /**
      * 删除${module}
      */
    @RequestMapping(value="/del.htm")
    @ResponseBody
    public String delete(HttpServletRequest request) throws Exception {
        String ${C.tableClass().pkName} = request.getParameter("${C.tableClass().pkName}");
        if(!Empty.isEmpty(${C.tableClass().pkName})){
            ${S.firstToLowerCase(C.className(T.SERVICE))}.delete(${C.tableClass().pkName});
            return "success";
        }else{
            return "null";
        }
    }
    /**
      * 修改${module}
      */
    @RequestMapping(value = "/modify.htm")
    public String modify(HttpServletRequest request, Model model) throws Exception {
    <#list C.tableClass().propertyDescList as property>
        <#if property.classSimpleName == "Date">
        SimpleDateFormat sDFormat = new SimpleDateFormat("yyyy-MM-dd");
            <#break>
        </#if>
    </#list>

    <#list C.tableClass().propertyDescList as property>
        <#if property.classSimpleName == "Date">
        String ${property.propertyName} = request.getParameter("${property.propertyName}");
        Date ${property.propertyName}Format = sDFormat.parse(${property.propertyName});
        <#elseif property.propertyName==C.tableClass().pkName>
        ${property.classSimpleName} ${property.propertyName} = request.getParameter("${property.propertyName}");
        <#else>
        ${property.classSimpleName} ${property.propertyName} = request.getParameter("${property.propertyName}");
        </#if>
    </#list>

        ${C.className(T.DOMAIN)} ${S.firstToLowerCase(C.className(T.DOMAIN))} = ${S.firstToLowerCase(C.className(T.SERVICE))}.findVO(${C.tableClass().pkName});
    <#list C.tableClass().propertyDescList as property>
        <#if property.classSimpleName == "Date">
        ${S.firstToLowerCase(C.className(T.DOMAIN))}.set${property.propertyNameUpCase}(${property.propertyName}Format);
        <#elseif property.propertyName==C.tableClass().pkName>
        <#else>
        ${S.firstToLowerCase(C.className(T.DOMAIN))}.set${property.propertyNameUpCase}(${property.propertyName});
        </#if>
    </#list>

        ${S.firstToLowerCase(C.className(T.SERVICE))}.save(${S.firstToLowerCase(C.className(T.DOMAIN))});
        return "/WEB-INF/jsp/oa/app/businessIndex_gwinsert.jsp";
    }

    @RequestMapping(value = "/review.htm")
    public String review(HttpServletRequest request, Model model) throws Exception {
        return "/WEB-INF/jsp/oa/app/businessIndex_gwinsert.jsp";
    }
}
